﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'user_concern';
domain = 'http://img1.chinalaohu.com';


/*
关注接口

请求	POST
 aID	拍品ID(必传)
 op	1: 关注; 0: 取消关注(必传)
 uuid	用户uuid(必传)
*/
</cfscript>

<cffunction name="gz" access="remote" returnFormat="json">
  <cfset rs = {"success":"0"}>
  
  <cfif isdefined('uuid') AND isdefined('aid') AND isdefined('op')>
    
    <cfif len(uuid) lt 32>
    	<!---,"msg":"错误的ID"--->
    	<cfset rs = {"success":"0","errCode":"0"}>
    <cfelse>
    	<!---根据UUID查找ID--->
      <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" />
      <cfif uuidgetuid.recordcount neq 1>
      	<!---,"msg":"用户ID错误"--->
      	<cfset rs = {"success":"0","errCode":"0"}>
      <cfelse>
      	<!---查找关注--->
        <cfset uid = uuidgetuid.uid>
        <cfquery datasource="#DB#" name="checkaidgz">
        select * 
        from 
        user_concern
        where uid=#uid# and aid='#aid#'
        </cfquery>
        <cfswitch expression="#op#">
          <!---关注--->
          <cfcase value="1">
            <cfif checkaidgz.recordcount gt 0>
            	<!---,"msg":"已经关注"}--->
              <cfset rs = {"success":"0","errCode":"-1"}>
            <cfelse>
              <cfquery datasource="#DB#">
              insert into #dbt#(uid,aid)
              values(#uid#,#aid#)
              </cfquery>
              <!---,"msg":"成功关注"--->
              <cfset rs = {"success":"1"}> 
            </cfif>
          </cfcase>
          <!---取消关注--->
          <cfcase value="0">
            <cfif checkaidgz.recordcount gt 0>
              <cfquery datasource="#DB#">
              delete from #dbt#
              where uid='#uid#' and aid='#aid#'
              </cfquery>
              <!---,"msg":"取消关注"--->
              <cfset rs = {"success":"1"}> 
            <cfelse>
            	<!---,"msg":"没有关注"--->
              <cfset rs = {"success":"0","errCode":"-1"}>
            </cfif>
          </cfcase>
        </cfswitch>
      
        </cfif>
      </cfif>
    <cfelse>
			<cfscript>
			//少参数
      rs = {"success":"0","errCode":"-1"};
      </cfscript>
    </cfif>
	<cfscript>
  rs = createObject("component",'cfjson').encode(rs);
  return rs;
  </cfscript>
</cffunction>


</cfcomponent>